﻿using Knlght.CH.Domain.IRepository;
using Knlght.Domain;
using Knlght.Model.Sys;
using Knlght.Web.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Knlght.Service
{
    public class LogInfoService : ServiceBase
    {       
        public ActionResponse Add(LogInfo model)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILogInfoRepository>();
                model.IPAddress = UrlHepler.Ip;
                return rp.Add(model);
            });
        }
        public ActionResponse Update(LogInfo model)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILogInfoRepository>();
                return rp.Update(model);
            });
        }
        public ActionResponse Update(QueryRequest<LogInfo> query, Expression<Func<LogInfo, LogInfo>> key)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILogInfoRepository>();
                return rp.UpdateToList(query, key);
            });
        }
        public ActionResponse Remove(QueryRequest<LogInfo> query)
        {
            return doAction(() =>
            {
                var rp = getRepository<ILogInfoRepository>();
                return rp.Delete(query);
            });
        }
        public PagingResponse<LogInfo> Paging(PagingRequest<LogInfo> request)
        {
            return GetPaging<LogInfo>(() => {
                //总记录
                int totalRecord = 0;
                var rp = getRepository<ILogInfoRepository>();         
                return new PagingList<LogInfo>()
                {
                    Models = rp.GetList(request.PageSize, request.PageIndex, out totalRecord,request.Query),
                    TotalModels = totalRecord,
                    TotalPages = (totalRecord + request.PageSize - 1) / request.PageSize
                };
            });
        }
    }
}
